package com.afd.ozblip.activity;

import com.afd.ozblip.entity.DishEntity;
import com.afd.ozblip.entity.RecDishEntity;
import com.afd.ozblip.image.LoadImage;
import com.afd.ozblip.util.Constants;
import com.afd.ozblip.util.StringUtil;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

public class DishDetailActivity extends BaseActivity {

	/****************** 视图变量 **************************/
	private TextView topTitleTv;
	private ImageView dishImageIv;
	private TextView dishNameTv;
	private TextView dishPriceTv;
	private TextView dishTypeTv;

	/****************** 数据变量 **************************/
	private DishEntity dishInfo;
	private LoadImage loadImage;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.dish_detail);
		// 启动返回功能
		toBack();
		// 寻找视图
		findViews();
		// 设置监听
		setListeners();
		// 获取参数
		getBundle();
		// 设置视图
		setViews();
	}

	/**
	 * 寻找视图
	 */
	public void findViews() {
		this.loadImage = new LoadImage(DishDetailActivity.this);
		this.topTitleTv = (TextView) findViewById(R.id.tv_business_recommend_topTitle);
		this.dishImageIv = (ImageView) findViewById(R.id.iv_business_recommend_image);
		this.dishNameTv = (TextView) findViewById(R.id.tv_business_recommend_dishName);
		this.dishPriceTv = (TextView) findViewById(R.id.tv_business_recommend_dishPrice);
		this.dishTypeTv = (TextView) findViewById(R.id.tv_business_recommend_dishType);
	}

	/**
	 * 设置监听
	 */
	public void setListeners() {
		View.OnClickListener dishDetailClick = new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				switch (v.getId()) {
				case R.id.ll_upload_dish:
					Intent settingIntent = new Intent(DishDetailActivity.this,
							UploadPhotoActivity.class);
					startActivity(settingIntent);
					break;

				default:
					break;
				}
			}
		};
	}

	/**
	 * 获取传递的参数
	 */
	private void getBundle() {
		Intent intent = getIntent();
		dishInfo = (DishEntity) intent
				.getSerializableExtra("dish");
	}

	/**
	 * 设置视图
	 */
	private void setViews() {
		if (dishInfo != null) {
			this.topTitleTv.setText(dishInfo.getBusinessName());
			String dishImageUrl = dishInfo.getDishImg();
			if(!StringUtil.isNullOrEmpty(dishImageUrl)){
				loadImage.addTask(Constants.WEB_PATH+dishImageUrl, dishImageIv);
			}
			this.dishNameTv.setText(dishInfo.getDishName());
			this.dishPriceTv.setText(dishInfo.getDishPrice());
			this.dishTypeTv.setText(dishInfo.getDishType());
		}
	}
}